	#include<iostream>
	#include<cstdio>
	using namespace std;
	int main()
	{
		int year, month, day;
		int t;
		scanf_s("%d", &t);
		while (t--) {
			int sum = 0;
			scanf_s("%d-%d-%d", &year, &month, &day);
			if (month == 2 && day == 29) {
				cout << -1 << endl;
				continue;
			}
			else if (month <= 2) {
				for (int n = year; n <= year + 17; n++) {
					if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0)) {
						sum += 366;
					}
					else {
						sum += 365;
					}
				}
			}
			else {
				for (int n = year + 1; n <= year + 18; n++) {
					if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0)) {
						sum += 366;
					}
					else {
						sum += 365;
					}
				}
			}
			printf("%d\n", sum);
		}
		return 0;
	}